<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      /**
       * @param {number[]} nums
       * @param {number} k
       * @return {void} Do not return anything, modify nums in-place instead.
       */
      var rotate = function (nums, k) {
        var l = nums.length; // l=2
        // 当移动次数大于数组长度，可以先取余数
        if (k > l) k = k % l;
        // var newNums = nums.splice(l - k); 
        nums.unshift(...nums.splice(l - k));
      };
      var nums = [1, 2];
      rotate(nums, 5);
      console.log(nums);
    </script>
  </body>
</html>
